using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using MacomberMap.Common.Components;
using MacomberMap.Common.User_Interfaces.One_Lines.Elements;

namespace MacomberMap.Common.User_Interfaces.Components
{
    /// <summary>
    /// This class holds the parameters for displaying one-lines
    /// </summary>
    public class MM_OneLine_Display
    {
        #region Variable declarations
        private bool _Names = true, _Percentages = true, _MVA = true, _MW = true, _MVAR = true, _OtherLine = true, _Voltage = true, _Taps = true, _EditorMode = false, _HighlightSynchroscopes = false, _InformationMode = false;
        private string _DataSource;

        /// <summary>One or more display parameters have changed</summary>
        public event EventHandler DisplayParameterChanged;

        /// <summary>
        /// Whether the user is allowed to edit one-line components
        /// </summary>
        [Category("Mode"), Description("Whether the user is allowed to edit one-line components")]
        public bool EditorMode
        {
            get { return _EditorMode; }
            set { _EditorMode = value; }
        }

        /// <summary>
        /// Whether the user is allowed to edit one-line components
        /// </summary>
        [Category("Mode"), Description("Whether the user is allowed to view details on one-line components")]
        public bool InformationMode
        {
            get { return _InformationMode; }
            set { _InformationMode= value; }
        }

        /// <summary>
        /// Whether the display is in DDL import mode.
        /// </summary>
        [Category("Mode"), Description("Whether the display is in DDL import mode."), DefaultValue(false)]
        public bool DDLImportMode
        {
            get { return _DDLImportMode; }
            set { _DDLImportMode = value; }
        }
        private bool _DDLImportMode = false;



        /// <summary>
        /// Whether linked components should be shown.
        /// </summary>
        [Category("Mode"), Description("Whether linked components should be shown."), DefaultValue(true)]
        public bool ShowLinkedComponents
        {
            get { return _ShowLinkedComponents; }
            set { _ShowLinkedComponents = value; }
        }
        private bool _ShowLinkedComponents=true;


        /// <summary>Whether components (without CIM linkages) should be shown</summary>
        [Category("Mode"), Description("Whether components (without CIM linkages) should be shown."), DefaultValue(true)]
        public bool ShowUnlinkedComponents
        {
            get { return _ShowUnlinkedComponents; }
            set { _ShowUnlinkedComponents = value; }
        }
        private bool _ShowUnlinkedComponents = true;


        /// <summary>Whether descriptive labels should be shown</summary>
        [Category("Mode"), Description("Whether descriptive labels should be shown."), DefaultValue(true)]
        public bool ShowDescriptives
        {
            get { return _ShowDescriptives; }
            set { _ShowDescriptives = value; }
        }
        private bool _ShowDescriptives = true;

        /// <summary>Whether connectivity nodes should be shown</summary>
        [Category("Mode"), Description("Whether connectivity nodes should be shown."), DefaultValue(true)]
        public bool ShowConnectivityNodes
        {
            get { return _ShowConnectivityNodes; }
            set { _ShowConnectivityNodes = value; }
        }
        private bool _ShowConnectivityNodes = true;

        /// <summary>Whether node to element lines should be shown</summary>
        [Category("Mode"), Description("Whether node to element lines should be shown."), DefaultValue(true)]
        public bool ShowNodeToElementLines
        {
            get { return _ShowNodeToElementLines; }
            set { _ShowNodeToElementLines = value; }
        }
        private bool _ShowNodeToElementLines = true;

        /// <summary>The collection of unlinked elements, and whether they should be shown individually</summary>
        public SortedDictionary<String, bool> UnlinkedElements = new SortedDictionary<string, bool>();



        /// <summary>
        /// Whether the tap levels should be shown
        /// </summary>
        [Category("Display"), Description("The predominant data source for our display")]
        public string DataSource
        {
            get { return _DataSource; }
            set { _DataSource = value; if (DisplayParameterChanged != null) DisplayParameterChanged(this, EventArgs.Empty); }
        }


        /// <summary>
        /// Whether the tap levels should be shown
        /// </summary>
        [Category("Display"), Description("Whether the tap levels should be shown"), DefaultValue(true)]
        public bool Taps
        {
            get { return _Taps; }
            set { _Taps = value; if (DisplayParameterChanged != null) DisplayParameterChanged(this, EventArgs.Empty); }
        }

        /// <summary>
        /// Whether the voltage levels should be shown
        /// </summary>
        [Category("Display"), Description("Whether the voltage levels should be shown"), DefaultValue(true)]
        public bool Voltage
        {
            get { return _Voltage; }
            set { _Voltage = value; if (DisplayParameterChanged != null) DisplayParameterChanged(this, EventArgs.Empty); }
        }

        /// <summary>
        /// Whether information on the other line should be shown
        /// </summary>
        [Category("Display"), Description("Whether information on the other line should be shown"), DefaultValue(true)]
        public bool OtherLine
        {
            get { return _OtherLine; }
            set { _OtherLine = value; if (DisplayParameterChanged != null) DisplayParameterChanged(this, EventArgs.Empty); }
        }

        /// <summary>
        /// Whether the MVARs should be shown
        /// </summary>
        [Category("Display"), Description("Whether the MVARs should be shown"), DefaultValue(true)]
        public bool MVAR
        {
            get { return _MVAR; }
            set { _MVAR = value; if (DisplayParameterChanged != null) DisplayParameterChanged(this, EventArgs.Empty); }
        }

        /// <summary>
        /// Whether the MWs should be shown
        /// </summary>
        [Category("Display"), Description("Whether the MWs should be shown"), DefaultValue(true)]
        public bool MW
        {
            get { return _MW; }
            set { _MW = value; if (DisplayParameterChanged != null) DisplayParameterChanged(this, EventArgs.Empty); }
        }

        /// <summary>
        /// Whether the MVAs should be shown
        /// </summary>
        [Category("Display"), Description("Whether the MVAs should be shown"), DefaultValue(true)]
        public bool MVA
        {
            get { return _MVA; }
            set { _MVA = value; if (DisplayParameterChanged != null) DisplayParameterChanged(this, EventArgs.Empty); }
        }

        /// <summary>
        /// Whether the MVAs should be shown
        /// </summary>
        [Category("Display"), Description("Whether the synchroscope titles should be highlighed"), DefaultValue(true)]
        public bool HighlightSynchroscopes
        {
            get { return _HighlightSynchroscopes; }
            set { _HighlightSynchroscopes = value; if (DisplayParameterChanged != null) DisplayParameterChanged(this, EventArgs.Empty); }
        }

        /// <summary>
        /// Whether the percentages should be shown
        /// </summary>
        [Category("Display"), Description("Whether the percentages should be shown"), DefaultValue(true)]
        public bool Percentages
        {
            get { return _Percentages; }
            set { _Percentages = value; if (DisplayParameterChanged != null) DisplayParameterChanged(this, EventArgs.Empty); }
        }

        /// <summary>
        /// Whether items' names should be shown
        /// </summary>
        [Category("Display"), Description("Whether items' names should be shown"), DefaultValue(true)]
        public bool Names
        {
            get { return _Names; }
            set { _Names = value; if (DisplayParameterChanged != null) DisplayParameterChanged(this, EventArgs.Empty); }
        }

        /// <summary>
        /// The base element for the display
        /// </summary>
        [Category("Display"), Description("The base element for the display")]
        public MM_Element BaseElement
        {
            get { return _BaseElement; }
            set { _BaseElement = value; }
        }
        private MM_Element _BaseElement;
        #endregion

        #region Event handling
        /// <summary>A one-line element has been added</summary>
        public event ElementActivityDelegate ElementsAdded;

        /// <summary>A one-line element has been assigned a parent</summary>
        public event ElementActivityDelegate ElementsAssigned;

        /// <summary>A one-line element has been removed</summary>
        public event ElementActivityDelegate ElementsRemoved;

        /// <summary>A one-line element has been selected</summary>
        public event ElementActivityDelegate ElementsSelected;

        /// <summary>A one-line node has been added</summary>
        public event NodeActivityDelegate NodesAdded;

        /// <summary>A one-line node has been removed</summary>
        public event NodeActivityDelegate NodesRemoved;

        /// <summary>A one-line node has been selected</summary>
        public event NodeActivityDelegate NodesSelected;

        /// <summary>
        /// A delegate for handling one-line additions
        /// </summary>
        /// <param name="Elements">The added one-line element</param>
        public delegate void ElementActivityDelegate(MM_OneLine_Element[] Elements);

        /// <summary>
        /// A delegate for handling one-line additions
        /// </summary>
        /// <param name="Nodes">The added one-line element</param>
        public delegate void NodeActivityDelegate(MM_OneLine_Node[] Nodes);
        #endregion

        #region Interfaces for the event handlers
        /// <summary>
        /// Handle element removal
        /// </summary>
        /// <param name="Elems"></param>
        public void HandleRemovedElements(MM_OneLine_Element[] Elems)
        {
            if (ElementsRemoved != null)
                ElementsRemoved(Elems);
        }

        /// <summary>
        /// Handle element addition
        /// </summary>
        /// <param name="Elems"></param>
        public void HandleAddedElements(MM_OneLine_Element[] Elems)
        {
            if (ElementsAdded != null)
                ElementsAdded(Elems);
        }

        /// <summary>
        /// Handle element assignment
        /// </summary>
        /// <param name="Elems"></param>
        public void HandleAssignedElements(MM_OneLine_Element[] Elems)
        {
            if (ElementsAssigned != null)
                ElementsAssigned(Elems);
        }


        /// <summary>
        /// Handle element selection
        /// </summary>
        /// <param name="Elems"></param>
        public void HandleSelectedElements(MM_OneLine_Element[] Elems)
        {
            if (ElementsSelected != null)
                ElementsSelected(Elems);
        }
        
        /// <summary>
        /// Handle Node removal
        /// </summary>
        /// <param name="Elems"></param>
        public void HandleRemovedNodes(MM_OneLine_Node[] Elems)
        {
            if (NodesRemoved != null)
                NodesRemoved(Elems);
        }

        /// <summary>
        /// Handle Node addition
        /// </summary>
        /// <param name="Elems"></param>
        public void HandleAddedNodes(MM_OneLine_Node[] Elems)
        {
            if (NodesAdded != null)
                NodesAdded(Elems);
        }

        /// <summary>
        /// Handle Node selection
        /// </summary>
        /// <param name="Elems"></param>
        public void HandleSelectedNodes(MM_OneLine_Node[] Elems)
        {
            if (NodesSelected != null)
                NodesSelected(Elems);
        }
        #endregion

    }
}
